﻿using System.Windows.Media.Media3D;

/// <summary>
/// Vector3D类的扩展方法类
/// </summary>
public static class Vector3DExtensions
{

    /// <summary>
    /// 查找给定三维向量的垂直向量
    /// </summary>
    /// <param name="v">三维向量</param>
    /// <returns>三维向量</returns>
    public static Vector3D FindAnyPerpendicular(this Vector3D v)
    {
        Vector3D u = Vector3D.CrossProduct(new Vector3D(0, 1, 0), v);
        if (u.LengthSquared < 1e-3)
        {
            u = Vector3D.CrossProduct(new Vector3D(1, 0, 0), v);
        }

        return u;
    }

    /// <summary>
    /// 将三维向量转为三维点
    /// </summary>
    /// <param name="v">三维向量</param>
    /// <returns>三维点</returns>
    public static Point3D ToPoint3D(this Vector3D v)
    {
        return new Point3D(v.X, v.Y, v.Z);
    }


}
